<?php
@header("Content-Type:text/json;charset=utf-8");
@header("Access-Control-Allow-Origin:*");
$conn = mysqli_connect("b-sjisyki6cozhtk.bch.rds.gz.baidubce.com:3306", "b_sjisyki6cozhtk", "12345678", "b_sjisyki6cozhtk");

if (!$conn) { // 如果连接失败 => 脚本在当前退出
    exit('{"status":false,"message":"数据库链接失败"}');
}
mysqli_query($conn, "set names utf8");
mysqli_query($conn, "set character set utf-8"); // 向数据库存数据时  将编码转为utf-8
if (!isset($_GET["user"])) {
    exit('{"status":false,"message":"请传入完整参数"}');
}

$phone = $_GET["user"];

$sql = "select * from `zhuce` where user = '$phone'";
$result = mysqli_query($conn, $sql);

$obj = array();
if ($result) { // 有结果对象 => 可能有数据

    $item = mysqli_fetch_assoc($result);
    // print_r($item === null);

    if (!$item) {
        $obj["status"] = true;
        $obj["message"] = "可以使用的手机号";
    } else {
        $obj["status"] = false;
        $obj["message"] = "手机号已存在!";
    }
} else {
    $obj["status"] = false;
    $obj["message"] = "sql语句有误";
    $obj["sql"] = $sql;
}
echo json_encode($obj);
